package com.kfm.exec;

public class MyStack extends Stack {
    Object[] arr;
    int count;
    int capacity = 10;

    public MyStack() {
        arr = new Object[capacity];
    }

    public MyStack(int capacity) {
        if (capacity <= 0) {
            capacity = 10;
        }
        this.capacity = capacity;
        arr = new Object[capacity];
    }

    @Override
    void push(Object element) {
        arr[count] = element;
        count++;
    }

    @Override
    Object pop() {
        // 删除数组 count-1位置的元素 1, 2, 3, 0, 0 , 0000
        Object remove = arr[count - 1];
        System.arraycopy(arr, 0, arr, 0, count - 1); // 0
        // 1 10 + 1
        System.arraycopy(arr, count, arr, count - 1, arr.length - count);
        count--;
        return remove;
    }

    @Override
    Object peek() {
        return null;
    }

    @Override
    boolean isEmpty() {
        return false;
    }

    @Override
    int size() {
        return 0;
    }
}
